#include<stdio.h>

typedef long long LL;
LL res;
int n;

int main() 
{ 
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i ++ )
	{
		if (!(i % 7)|| i % 10 == 7 || i / 10 == 7) continue ;
		
		res += i * i;
	}
	
	printf("%lld", res);
	 	
    return 0;
 }
